	<table width="100%"border="0" cellpadding="0" cellspacing="0">
	 <tr><td colspan="3" bgcolor="#333333"></td></tr>
	  <tr>
		<td width="77%" valign="top" style="padding-top:10px; padding-left:10px "><?
	//$url=$_SERVER['PHP_SELF']; 
	$url=$_SERVER['HTTP_HOST'].$_SERVER['QUERY_STRING']; 
	if (eregi("contacts.php",$url)) {	
	die("&nbsp;");
	}
	//check_gpc();
	 
	$template_products_body="template/product_list.tpl";
	$template_contactList="template/contact_list.tpl";
	$template_memContact="template/memContact.tpl";
	$template_guestContact="template/guestContact.tpl";
	
	$base_url 	= 'index.php';
	
	$url = substr($url,strpos($url,".php"),strlen($url));
	$url = explode("/",$url);
	
	$mode = isset($url[2]) ? $url[2] : '' ;
	 
	 switch($mode){ 
		  case "delete":
			 deleteContact();
			 break;
		  case "send":
			  sendContact();
			  break;
		  case "gsend":
			  SendGuestContact();
			  break;
		  default:
			  viewcontact(); 
			  break; 
	 } 
	 
	
	function viewcontact(){
		global $template, $db, $template_products_body,$base_url,$site_base_href,$mode; 
		 
		$type=isset($_POST["type"]) ? htmlspecialchars($_POST["type"]) : ''; 
		$typev=isset($_GET["type"]) ? htmlspecialchars($_GET["type"]) : ''; 
		if($type=="addToCard" || $mode=="addToCard"){
			AddToBasket();
			return;
		}
		$ses_login = isset($_SESSION['ses_login']) ? $_SESSION['ses_login'] : '' ;
		if(!empty($ses_login["s_user"])){
			memContact();
			return;
		}else{
			guestContact();
			return;
		}	 
	}
	//============================================================================================================
	function AddToBasket(){
		global $db,$template_contactList,$site_base_href,$base_url,$template;
		$chkcontactonly	= isset($_POST["oldurl"]) ? htmlspecialchars($_POST["oldurl"]) : '';	
	
		addCart();
		 
		$ses_pros=$_SESSION["ses_pros"];
		
		if(!empty($chkcontactonly)){
		//  redirect($site_base_href.$chkcontactonly);
		}
		
		redirect($site_base_href.'/index.php?ids=21dbf14c7fa986fdafe8983b21d1c843&lang=us&/contact/addToCard');
		return;
		/*
		$sql='select s.memID,s.proID,s.ProductName,p.CompanyName,p.countryID from vb_products s inner join vb_member m on m.memID=s.memID inner join vb_memberprofile p on m.memID=p.memID
		where s.proID=-1';
		if(is_array($ses_pros)){
		
			while (list($id,) = each($ses_pros)){
				$id	= intval($id);
				if ($id){
					$sql.=" or s.proID=".$id;
				}
			}
			 
	 
		if(!$result=$db->sql_query($sql)){
		  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
		}	
		$cust_count=$db->sql_numrows($result);
		$cust_data=$db->sql_fetchrowset($result);	
		$db->sql_freeresult($result);	
		
		for($i=0;$i<$cust_count;$i++){
				$template->assign_block_vars("ContactList", array(							
					'subject' =>$cust_data[$i]["ProductName"],
					'url' => $site_base_href.'/supplier.php?supplier='.$cust_data[$i]["memID"].'&act=vleads&mode=leadsdetail&lid='.$cust_data[$i]["lID"],
					'company'	=>$cust_data[$i]["CompanyName"],
					'country' =>getContry($cust_data[$i]["countryID"]),				
					'CHECKBOX'	 => '<input type="Checkbox" name="proid['.$cust_data[$i]["lID"].']" value="'. $cust_data[$i]["proID"] .'" checked />'
				));
			}
		}
		$template->assign_vars(array(	
			'S_ACTION' =>$site_base_href.'/index.php?/contacts',
			'c_delete' =>$site_base_href.'/index.php?/contacts/delete'
		));
		
		$template->set_filenames(array(
			'body' =>$template_contactList
			));
		$template->pparse('body');		
		*/
	}
	function guestContact(){
		global $template,$template_guestContact,$base_url,$site_base_href;
		$chkcontactonly	= isset($_POST["chkSes"]) ? intval($_POST["chkSes"]) : 0;	
		 getContry();
		 addCart();
	
		$i=rand(4,5);
		$id_random = '' ;
		for($j=0;$j<$i;$j++){
			$id_random .= chr(rand(65,90));
		}
		
		if($chkcontactonly){
			$ses_pro  = isset($_SESSION["ses_pro1"]) ? $_SESSION["ses_pro1"] : '' ;
			$ses_pros = isset($_SESSION["ses_pros1"]) ? $_SESSION["ses_pros1"] : '' ;
		}else{
			$ses_pro  = isset($_SESSION["ses_pro"]) ? $_SESSION["ses_pro"] : '' ;
			$ses_pros = isset($_SESSION["ses_pros"]) ? $_SESSION["ses_pros"] : '' ;
		}
		$ses = '' ;
		if(is_array($ses_pro)){	
			$ses=count($ses_pro);
		}
		if(is_array($ses_pros)){	
			$ses+=count($ses_pros);
		}
		if($ses>1){
			$comp='<a href="javascript:void(0)" onClick="displayDiv()">'.$ses.' Company </a>';
		}else{
			$comp=getCompany();
		}
		
		$template->assign_vars(array(
			'company' =>$comp,
			'ranima' => base64_encode(base64_encode($id_random)),
			'hdranima' =>$id_random,
			'con_company' =>getCompany(),
			'getImage' =>$site_base_href.'/',
			'chkSes'=>	$chkcontactonly,
			's_action'	=>$site_base_href."/".$base_url."?/contact/gsend/"		
		));
		
		$template->set_filenames(array(
			'body' =>$template_guestContact
			));
		$template->pparse('body');		
		 
	}
	function memContact(){
		global $template,$template_memContact,$site_base_href,$base_url;
		
		addCart();
		$chkcontactonly	= isset($_POST["chkSes"]) ? intval($_POST["chkSes"]) : 0;	
		if($chkcontactonly){
			$ses_pro=$_SESSION["ses_pro1"];
			$ses_pros=$_SESSION["ses_pros1"];
		}else{
			$ses_pro=$_SESSION["ses_pro"];
			$ses_pros=$_SESSION["ses_pros"];
		}
		if(is_array($ses_pro)){	
		 $ses=count($ses_pro);
		}
		if(is_array($ses_pros)){	
		 $ses+=count($ses_pros);
		}
		
		if($ses>1){
			$comp='<a href="javascript:void(0)" onClick="displayDiv()">'.$ses.' Company </a>';
		}else{
			$comp=getCompany();
		}
		$template->assign_vars(array(
			'company' =>$comp,
			'con_company' =>getCompany(),
			'chkSes'=>	$chkcontactonly,
			's_action'	=>$site_base_href."/".$base_url."?/contact/send/"		
		));
		
		$template->set_filenames(array(
			'body' =>$template_memContact
			));
		$template->pparse('body');		
		unset($ses_pros);
	
	}
	function getCompany(){
		global $db;
		
		$chkcontactonly	= isset($_POST["chkSes"]) ? intval($_POST["chkSes"]) : 0;	
		if($chkcontactonly){		
			$ses_pros = isset($_SESSION["ses_pros1"]) ? $_SESSION["ses_pros1"] : '' ;
		}else{
			$ses_pros = isset($_SESSION["ses_pros"]) ? $_SESSION["ses_pros"] : '' ;
		}
		
		$comName='';
	
		$sql='select  m.CompanyName,p.proID from vb_memberprofile m inner join vb_products p on m.memID=p.memID where p.proID=-1';
		while (list(, $id) = each($ses_pros)){
			$id	= intval($id);
			if ($id){
				$sql.=" or p.proID=".$id;
			}
		}
			 
	 
		if(!$result=$db->sql_query($sql)){
		  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
		}
		$comp=array();
		$cust_count=$db->sql_numrows($result);
		$cust_data=$db->sql_fetchrowset($result);	
		$db->sql_freeresult($result);	
		for($i=0;$i<$cust_count;$i++){
			$comp[$cust_data[$i]["proID"]]=$cust_data[$i]["CompanyName"];
		} 
		$cust_data=array();
		 if($chkcontactonly){		
			$ses_pros=$_SESSION["ses_pros1"];
		}else{		
			$ses_pros=$_SESSION["ses_pros"];
		}
		while (list(, $id) = each($ses_pros)){
			$id	= intval($id);			
			if ($id){
				$comName.=$comp[$id]."<br>";
			}
		}
		if($chkcontactonly){
			$ses_pro = isset($_SESSION["ses_pro1"]) ? $_SESSION["ses_pro1"] : '' ;		 
		}else{
			$ses_pro = isset($_SESSION["ses_pro"]) ? $_SESSION["ses_pro"] : '' ;
		}
		if($ses_pro){
		$sql='select  m.CompanyName,p.proID from vb_memberprofile m inner join vb_products p on m.memID=p.memID where p.proID=-1';
			while (list(, $id) = each($ses_pro)){
				$id	= intval($id);
				if ($id){
					$sql.=" or p.proID=".$id;
				}
			}
		 
		if(!$result=$db->sql_query($sql)){
			message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
		}
		$comp=array();
		$cust_count=$db->sql_numrows($result);
		$cust_data=$db->sql_fetchrowset($result);	
		$db->sql_freeresult($result);	
		for($i=0;$i<$cust_count;$i++){
			$comp[$cust_data[$i]["proID"]]=$cust_data[$i]["CompanyName"];
		}
		$cust_data=array();
		if($chkcontactonly){
			$ses_pro = isset($_SESSION["ses_pro1"]) ? $_SESSION["ses_pro1"] : '' ;		 
		}else{
			$ses_pro = isset($_SESSION["ses_pro"]) ? $_SESSION["ses_pro"] : '' ;
		}
			while (list(,$id) = each($ses_pro)){
				$id	= intval($id);			 
				if ($id){
					$comName.=$comp[$id]."<br>";
				}
		 	}
		}	 
		return $comName;
	}
	function addCart(){	
		$proid	= isset($_POST["proid"]) ? $_POST["proid"] : '';
		$chkcontactonly	= isset($_POST["chkSes"]) ? intval($_POST["chkSes"]) : 0;	
		
		//if($chkcontactonly){
		//}
		
		if ( !empty($proid) ){
			if ( !is_array($proid) ){
				$pro_id[0]	= $proid;
			}else{
				$pro_id	= $proid;
			}
			unset($proid);
			
			if(!isset($_SESSION["ses_pros"])){
				session_register("ses_pros");		
			}	
			
			$ses_pros=$chkcontactonly ? '' :  $_SESSION["ses_pros"];
			
			 if(count($ses_pros)>38){
				return;
			}
			while (list($id, $value) = each($pro_id)){
				$id	= intval($id);
				if ($id){
					$ses_pros[$id]=$value;					 
				}
			}	
			if($chkcontactonly){
				$_SESSION['ses_pros1']=$ses_pros;	
			}else{
			$_SESSION['ses_pros']=$ses_pros;	
			}
		}
		return;
		
	}
	function deleteContact()
	{	
		 global $site_base_href;
		$proid	= isset($_POST["proid"]) ? $_POST["proid"] : '';
		
		$ses_pros=$_SESSION["ses_pros"];		
		if ( !empty($proid) ){
			if ( !is_array($proid) ){
				$pro_id[0]	= $proid;
			}
			else{
				$pro_id	= $proid;
			}
			unset($proid);	
			
			while (list($id, $value) = each($pro_id)){
				$id	= intval($id);
				if ($value){
					unset($ses_pros[$id]);			
					
				}
			}		
			$_SESSION['ses_pros']=$ses_pros;		
		}
		
		redirect($site_base_href."/index.php?/contact/addToCard");
	}
	?></td>
		<td  bgcolor="#333333"></td>
		<td width="23%" valign="top" style="padding-top:10px "><table width="200" border="0">
		  <tr>
			<td style="padding-left:10px "><strong>Categories</strong></td>
		  </tr>
		  <tr>
			<td style="padding-left:10px "><? include "uproducts.php"?></td>
		  </tr>
		</table></td>
	  </tr>
	</table>
